# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=xfsprogs
pkgver=6.5.0
pkgrel=0
pkgdesc="XFS filesystem utilities"
url="https://xfs.org/index.php/Main_Page"
arch="all"
license="LGPL-2.1-or-later"
makedepends="
	attr-dev
	bash
	inih-dev
	linux-headers
	python3
	userspace-rcu-dev
	util-linux-dev
	"
options="!check"  # no test suite
subpackages="$pkgname-dev $pkgname-doc $pkgname-libs $pkgname-extra"
source="https://mirrors.edge.kernel.org/pub/linux/utils/fs/xfs/xfsprogs/xfsprogs-$pkgver.tar.xz
	lfs64.patch
	"

build() {
	export DEBUG=-DNDEBUG
	export OPTIMIZER="$CFLAGS -flto=auto"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sbindir=/sbin \
		--libexecdir=/usr/lib \
		--enable-gettext=no
	make
}

package() {
	make -j1 DIST_ROOT="$pkgdir" install install-dev
	rm -v "$pkgdir"/lib/libhandle.la
	mv "$pkgdir"/sbin "$pkgdir"/usr
	mkdir -p "$pkgdir"/sbin
	for i in mkfs.xfs fsck.xfs xfs_repair; do
		mv "$pkgdir"/usr/sbin/$i "$pkgdir"/sbin/
	done
	chown -R root:root "$pkgdir"/*
}

extra() {
	depends="$pkgname python3" # python3 for xfs_scrub_all
	pkgdesc="XFS filesystem extra utilities"

	# shellcheck disable=2115
	rm -rf "$pkgdir"/lib "$pkgdir"/usr/lib
	amove usr/
}

sha512sums="
0a2db9c3df8209b2b6d264b7ef87f4c101f5129dfa14cb09159dbef181c09508fa8460eb1f4293300f24696ce236ca49065e47068cebdee00ee8ab9e2b75211c  xfsprogs-6.5.0.tar.xz
1512a5fb71aff2a33e6f2fc04d0eab9b53f534d15aa4335257aaec458ea929404669a8ebe86076e10229a1da3e6050a2988607dc57596e26ea214df994082f38  lfs64.patch
"
